/*
 *      Fischer Chess Club
 *      Copyright (c) 2010 Ryan Chiu
 *      All rights reserved.
 *      
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fischer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Database {
	public static Connection con;
	public static void connect() throws Exception
	{
		 Class.forName("com.mysql.jdbc.Driver").newInstance();
		 con = DriverManager.getConnection(
	                "jdbc:mysql://localhost:3306/db", "root", "apple2");   // Connect to player db
		 con.prepareStatement("use db;");
	}
    public static ResultSet query(String query) throws Exception
    {  
        PreparedStatement statement = con.prepareStatement(query);
        ResultSet result = statement.executeQuery();
        return result;
    }
    public static String[] toArray(ResultSet res) throws Exception
    {
        int i = 0;
        String[] array = new String[res.getMetaData().getColumnCount()];
        while (res.next())
        {
            array[i] = res.getString(i);
            i++;
        }
        return array;
    }
}
